local dingmou = fk.CreateSkill{
    name = "XD__dingmou"
}
Fk:loadTranslationTable{
    ["XD__dingmou"] = "定谋",
    [":XD__dingmou"] = "当你于出牌阶段连续使用三张非锦囊牌后，你可以视为使用一张普通锦囊牌，若你以此法使用的牌不是第一次以此法使用，你减1点体力上限。",
    ["@[XD__dingmou]"] = "定谋",
    ["#XD__dingmou"] = "定谋：你可以视为使用一张普通锦囊牌",
}

Fk:addQmlMark{
    name = "XD__dingmou",
    how_to_show = function (name, value, player)
        local num = player:getMark("XD__dingmou-phase")
        return num.."/3"
    end,
    qml_data = function (name, value, player)
        return player:getTableMark("XD__dingmou")
    end,
    qml_path = function (name, value, player)
        if #player:getTableMark("XD__dingmou") > 0 then
            return "packages/utility/qml/ViewPile"
        else
            return " "
        end
    end,
}

dingmou:addEffect(fk.CardUseFinished, {
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(dingmou.name) and player == target and player.phase == Player.Play and player:getMark("XD__dingmou-phase") > 2
    end,
    on_cost = function (self, event, target, player, data)
        local names = Fk:getAllCardNames("t")
        local use = player.room:askToUseVirtualCard(player, {
            name = names,
            skill_name = dingmou.name,
            prompt = "#XD__dingmou",
            skip = true,
        })
        if use then
            event:setCostData(self, use)
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "XD__dingmou-phase", 0)
        local use = event:getCostData(self)
        room:useCard(use)
        if table.contains(player:getTableMark("XD__dingmou"), use.card.trueName) then
            room:changeMaxHp(player, -1)
        end
        room:addTableMarkIfNeed(player, "XD__dingmou", use.card.trueName)
    end,

    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(dingmou.name) and player == target and player.phase == Player.Play
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if data.card.type == Card.TypeTrick then
            room:setPlayerMark(player, "XD__dingmou-phase", 0)
        elseif player:getMark("XD__dingmou-phase") < 3 then
            room:addPlayerMark(player, "XD__dingmou-phase", 1)
        end
    end,
})
dingmou:addEffect(fk.EventPhaseStart,{
    can_refresh = function (self, event, target, player, data)
        return player:getMark("@[XD__dingmou]") > 0
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:setPlayerMark(player, "@[XD__dingmou]", 1)
    end,
})
dingmou:addAcquireEffect(function (self, player, is_start)
    player.room:setPlayerMark(player, "@[XD__dingmou]", 1)
end)
dingmou:addLoseEffect(function (self, player, is_death)
    player.room:setPlayerMark(player, "@[XD__dingmou]", 0)
end)

return dingmou